#include <cstdio>

struct Student {
	char name[15];
	char no[15];
	int score; 
};

int main() {
	Student stu_high;
	Student stu_low;
	int n;
	scanf("%d", &n);
	if (n==0) return 0;
	scanf("%s%s%d", stu_high.name, stu_high.no, &stu_high.score);
	stu_low = stu_high;
	n--;
	while (n--) {
		Student stu_temp;
		scanf("%s%s%d", stu_temp.name, stu_temp.no, &stu_temp.score);
		if (stu_temp.score > stu_high.score) stu_high = stu_temp;
		if (stu_temp.score < stu_low.score) stu_low = stu_temp;
	}
	printf("%s %s\n%s %s\n", stu_high.name, stu_high.no, stu_low.name, stu_low.no);
	return 0;
}
